<?php
//a useful tool for showing the HTTP headers being sent by the server
header("X-Transporrent: supplement-your.domain.here/path/to/test.torrent");
?>
<html>
<head>
<title>
HTTP headers
</title>
<script type="text/javascript">
function readHTTPHeaders (url) {
   alert("not implemented");
   return "";
}

</script>
<script type="text/jscript">
function readHTTPHeaders (url) {
   try {
     var httpRequest = new ActiveXObject('Microsoft.XMLHTTP');
     httpRequest.open('HEAD', url, false);
     httpRequest.send();
     return httpRequest.getAllResponseHeaders();
   }
   catch (e) {
     alert("error trying to create/use Microsoft.XMLHTTP");
     return "";
   }
}

</script>
<script type="text/javascript; version=1.5">
function readHTTPHeaders (url) {
   try {
   //would be nice to do this without calling HEAD
     var httpRequest = new XMLHttpRequest();
     httpRequest.open('HEAD', url, false);
     httpRequest.send(null);
     return httpRequest.getAllResponseHeaders();
   }
   catch (e) {
     alert("error trying to create/use XMLHttpRequest");
     return "";
   }
}
function findTransporrent (headers) {
   var relevantLine = headers.match(/X-Transporrent:\s[^\n]*/)[0];
   return relevantLine.replace(/X-Transporrent:\ssupplement-/, "http://");
}

</script>
</head>
<body>
<form name="gui">
Enter (relative !) URL:
<input type="text" name="url" size="40"
        value="displayheaders.php"
/>
<input type="button" value="read headers"
        onclick="var headers = readHTTPHeaders(this.form.url.value);
                 this.form.output.value = findTransporrent(headers);"
/>
<br />
<textarea name="output" rows="10" cols="80"></textarea>
</form>
</body>
</html> 